import com.google.zxing.*;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;

/**读取二维码内容
 * Created by ${chengwengao} on 2017/1/22.
 */
public class ReadQRcode {
    public static void main(String[] args){
        MultiFormatReader multiFormatReader = new MultiFormatReader();
//        File file = new File("D:/QR.PNG");
//        File file = new File("D:/qrcode.png");
        File file = new File("D:/jqueryqrcode.png");
        try {
            BufferedImage image = ImageIO.read(file);
            BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(image)));
            //定义二维码参数
            HashMap hints = new HashMap();
            hints.put(EncodeHintType.CHARACTER_SET,"utf-8");
            Result result = multiFormatReader.decode(binaryBitmap, hints);
            System.out.println("解析结果："+result.toString());
            System.out.println("二维码格式类型："+result.getBarcodeFormat());
            System.out.println("二维码文本内容："+result.getText());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
